<#
 * FileName: Microsoft.PowerShell_profile.ps1
 * Author: 刘 鹏
 * Email: littleNewton6@outlook.com
 * Date: 2021, Aug. 21
 * Copyright: No copyright. You can use this code for anything with no warranty.
#>

#-------------------------------  SET Environment Variables BEGIN  -------------------------------

$env:path = "$env:path;E:\ipmitool"
$env:PYTHONSTARTUP = "$HOME/.pythonstartup.py"

$gitee_folders = ("F:\gitee", 'D:\E000-learningMaterials\E000-learningMaterials\gitee')
foreach($folder in $gitee_folders){
    if(Test-Path "$folder"){
        $gitee_folder = "$folder"
        $env:Path="$env:Path;${folder}\tools\PowerShell\Scripts"
        $env:PSModulePath += ";${folder}\tools\powershell\Modules"
        break
    }
}

#-------------------------------  SET Environment Variables END   -------------------------------


#------------------------------- Import Script BEGIN -------------------------------

# Automation
$clx_162 = "ipmitool -H 172.22.27.162 -U root -P root -I lanplus "
$starlake_149 = 'ipmitool -H 172.22.27.149 -U root -P root -I lanplus '

# BMCQA
$kuaishou_177 = 'ipmitool -I lanplus -H 172.22.12.177 -U root -P Ucloud.cn '
$kunlun_147 = 'ipmitool -I lanplus -H 172.22.12.147 -U root -P root '
$starlake_152 = 'ipmitool -I lanplus -H 172.22.12.152 -U root -P root '
$meituan_208 = 'ipmitool -H 172.22.12.208 -U root -P "M9&nj4Y3t" -I lanplus '
$apple_252 = "ipmitool -H 172.22.8.252 -U Administrator -P jumpm3 -I lanplus"

$chcp = "936, 65001"

function ipmi_cmd([string]$cmd) {

    $servers = @($clx_162, $starlake_149, $kuaishou_177, $kunlun_147, $starlake_152, $meituan_208)

    foreach ($server in $servers) {
        echo "$server  $cmd"
        $output = Invoke-Expression ($server + $cmd)
        echo "output: $output"
        echo ''
        echo ''
    }
}

$python_c = 'python -c "import sys; print(sys.path)"'



$module_folders = ("F:\gitee\tools\powershell\Scripts", 'D:\E000-learningMaterials\E000-learningMaterials\gitee\tools\powershell\Scripts')
foreach($folder in $module_folders){
    if(Test-Path "$folder"){
        $module_folder = "$folder"
        break
    }
}
# $ps1_items = (Get-ChildItem -Path $module_folder).FullName | Where-Object -FilterScript {($_).EndsWith('ps1')}
# foreach($item in $ps1_items){
#  . "$item"
# }



#------------------------------- Import Script End -------------------------------


#------------------------------- Import Modules BEGIN -------------------------------

# 引入 posh-git
Import-Module posh-git

# 引入 oh-my-posh
Import-Module oh-my-posh

# 设置 PowerShell 主题
# Set-PoshPrompt ys
# Set-PoshPrompt paradox
# Set-PoshPrompt -Theme Paradox
Set-PoshPrompt -Theme Powerlevel10k_Classic


# 引入 ps-read-line
Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource History
Set-PSReadlineKeyHandler -Key "Tab" -Function MenuComplete
Set-PSReadlineKeyHandler -Key "UpArrow" -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key "DownArrow" -Function HistorySearchForward
Set-PSReadLineOption -Colors @{ InlinePrediction = '#898c5b' }
Set-PSReadlineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key "RightArrow" -ScriptBlock {
    param($key, $arg)

    $line = $null
    $cursor = $null
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)

    if ($cursor -lt $line.Length) {
        [Microsoft.PowerShell.PSConsoleReadLine]::ForwardChar($key, $arg)
    }
    else {
        [Microsoft.PowerShell.PSConsoleReadLine]::AcceptNextSuggestionWord($key, $arg)
    }
}

Set-PSReadLineKeyHandler -Key End -ScriptBlock {
    param($key, $arg)

    $line = $null
    $cursor = $null
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)

    if ($cursor -lt $line.Length) {
        [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine($key, $arg)
    }
    else {
        [Microsoft.PowerShell.PSConsoleReadLine]::AcceptSuggestion($key, $arg)
    }
}

Import-Module Get-ChildItemColor
Import-Module psscheduledjob -SkipEditionCheck

Import-Module Custom-Function

#------------------------------- Import Modules END   -------------------------------

#------------------------------- Run Command Start   -------------------------------



# print system infomation
#neofetch

#------------------------------- run Command END   -------------------------------





